﻿package mortal.game.view.medal.view
{
    import Message.DB.Tables.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.medal.*;

    public class MedalCatagoryRender extends GCellRenderer
    {
        private var _medalList:Dictionary;
        private var _tipsTxt:GTextFiled;
        private var _notOpenTxt:GTextFiled;
        private var _notOpenBg:GImageBitmap;
        private var _medalVec:Array;

        public function MedalCatagoryRender()
        {
            this._medalVec = new Array();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.medalWinTitleBg, 0, 0, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.medalWinSpliteLine, 131, 4, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.medalWinSpliteLine, 246, 4, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.medalWinSpliteLine, 361, 4, this));
            this._tipsTxt = UIFactory.gTextField("", 270, 5, 220, 20, this, GlobalStyle.textFormatHuang2.center());
            this._notOpenBg = UIFactory.gImageBitmap(ImagesConst.medalCatagroyBg, 143, 60, this);
            this._notOpenTxt = UIFactory.gTextField("", 113, 73, 300, 20, this, GlobalStyle.textFormatHui.center());
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tipsTxt.dispose(param1);
            this._tipsTxt = null;
            this._notOpenBg.dispose(param1);
            this._notOpenBg = null;
            this._notOpenTxt.dispose(param1);
            this._notOpenTxt = null;
            this.removeList();
            this._medalList = new Dictionary();
            this._medalVec.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_3:TMedal = null;
            var _loc_4:MedalCache = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            super.data = param1;
            this._medalList = param1.list as Dictionary;
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            if (_loc_2 >= (this._medalList[1][0] as TMedal).roleLevel)
            {
                _loc_4 = Cache.instance.medal;
                while (_loc_6 < 4)
                {
                    
                    _loc_3 = this._medalList[(_loc_6 + 1)][0] as TMedal;
                    if (_loc_4.getOwnMedalByCatagoryAndType(_loc_3.catagory, _loc_3.type))
                    {
                        _loc_5++;
                    }
                    _loc_6++;
                }
                this._tipsTxt.text = "[" + _loc_5 + "/" + 4 + "]";
                this._tipsTxt.x = 390;
                this._notOpenBg.visible = false;
                this._notOpenTxt.text = "";
                this.updateMedalList();
            }
            else
            {
                this._tipsTxt.htmlText = Language.getStringByParam(35402, (this._medalList[1][0] as TMedal).roleLevel);
                this._tipsTxt.x = 152;
                this._notOpenBg.visible = true;
                this._notOpenTxt.text = Language.getStringByParam(35403, (this._medalList[1][0] as TMedal).roleLevel);
                this.removeList();
            }
            return;
        }// end function

        private function updateMedalList() : void
        {
            var _loc_1:MedalRender = null;
            var _loc_2:TMedal = null;
            var _loc_3:TMedal = null;
            var _loc_4:int = 0;
            while (_loc_4 < 4)
            {
                
                _loc_2 = this._medalList[(_loc_4 + 1)][0] as TMedal;
                _loc_3 = Cache.instance.medal.getOwnMedalByCatagoryAndType(_loc_2.catagory, _loc_2.type);
                _loc_1 = this._medalVec[_loc_4] as MedalRender;
                if (_loc_1 == null)
                {
                    _loc_1 = UICompomentPool.getUICompoment(MedalRender);
                    _loc_1.x = _loc_4 * 115 + 10;
                    _loc_1.y = -4;
                    this.addChild(_loc_1);
                    this._medalVec.push(_loc_1);
                }
                if (_loc_3)
                {
                    _loc_1.update(_loc_3);
                    _loc_1.toolTipData = _loc_3;
                }
                else
                {
                    _loc_1.update(_loc_2);
                    _loc_1.toolTipData = _loc_2;
                }
                _loc_4++;
            }
            return;
        }// end function

        private function removeList() : void
        {
            var _loc_1:MedalRender = null;
            for each (_loc_1 in this._medalVec)
            {
                
                _loc_1.dispose(true);
            }
            return;
        }// end function

    }
}
